package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4FlatMap {
  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf()
      .setAppName("map")
      .setMaster("local")

    //spark  上下文对象
    val sc = new SparkContext(conf)

    val lineRDD: RDD[String] = sc.parallelize(List("java,spark,hadoop", "spark,java,hadoop"))


    /**
      * flatMap： 将一行转换成多行
      *
      */

    val wordsRDD: RDD[String] = lineRDD.flatMap(line => {
      println("flatMap:" + line)
      line.split(",")
    })

    wordsRDD.foreach(println)

  }

}
